//
//  LocationService.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/9/12.
//  Copyright © 2018年 海格尔. All rights reserved.
//
#import "LocationService.h"

@implementation LocationService
+ (instancetype)shareInstance{
    static LocationService *location = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        location = [[LocationService alloc] init];
    });
    return location;
}

#pragma mark ==========配置信息==========
- (void)configurationParameter{
    [[BMKLocationAuth sharedInstance] checkPermisionWithKey:BAIDU authDelegate:self];
    //初始化实例
    self.locationManager = [[BMKLocationManager alloc] init];
    //设置delegate
    self.locationManager.delegate = self;
    //设置返回位置的坐标系类型
    self.locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;
    //设置距离过滤参数
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    //设置预期精度参数
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    //设置应用位置类型
    self.locationManager.activityType = CLActivityTypeAutomotiveNavigation;
    //设置是否自动停止位置更新
    self.locationManager.pausesLocationUpdatesAutomatically = NO;
    //设置是否允许后台定位
    //_locationManager.allowsBackgroundLocationUpdates = YES;
    //设置位置获取超时时间
    self.locationManager.locationTimeout = 10;
    //设置获取地址信息超时时间
    self.locationManager.reGeocodeTimeout = 10;
}


#pragma mark ==========单次定位==========
- (void)openLocationWithBlock:(LocationServiceBlock)block{
    [self.locationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
        if (location) {//得到定位信息，添加annotation
            if (location.rgcData) {
                if (block) {
                    block(location.rgcData.city,location.rgcData.adCode);
                }
            }
        }
        //网络状态
        NSLog(@"当前网络状态 = %d",state);
    }];
}




@end
